package ten;

public class DoubleCheckedLocking {
    private volatile static DoubleCheckedLocking instance;

    public DoubleCheckedLocking() {
    }

    public static DoubleCheckedLocking getInstance(){
        if(null != instance){
            return instance;
        }
        synchronized (DoubleCheckedLocking.class){
            if(null == instance){
                instance = new DoubleCheckedLocking();
            }
        }
        return instance;
    }

    public static void main(String[] args) {
        new Thread(()->{
            System.out.println(DoubleCheckedLocking.getInstance());
        }).start();
        System.out.println(DoubleCheckedLocking.getInstance());
    }
}
